import os

import yaml


class Settings:
    def __init__(self, config_path=None):
        if config_path is None:
            config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.yaml')
        with open(config_path, 'r', encoding='utf-8') as f:
            config = yaml.safe_load(f)
        self.db_host = config.get('db_host')
        self.db_user = config.get('db_user')
        self.db_password = config.get('db_password')
        self.db_name = config.get('db_name')
        self.knowledge = config["knowledge"]
        self.openai_base_url = config.get('openai_base_url')
        self.openai_api_key = config.get('openai_api_key')
        self.openai_model = config.get('openai_model')
        self.header_scan_limit = config.get('header_scan_limit', 10)
        self.desc_col_aliases = config.get('desc_col_aliases',
                                           ["Business Scenario Description", "Requirement Description"])
        self.support_col_aliases = config.get('support_col_aliases', ["DC Support", "DC Supports", "Supported by DC?"])
        self.confidence_col_aliases = config.get('confidence_col_aliases', ["Confidence Score(0-1)", "Confidence"])
        self.source_col_aliases = config.get('source_col_aliases', ["Knowledge Source", "Top 3 with source reference"])
        self.summary_col_aliases = config.get('summary_col_aliases', ["Response Summary", "Summary"])
        self.no_support_summary = config.get('no_support_summary',
                                             "Sorry, but I don't have enough information to answer")
        self.smtp_host = config.get('smtp_host')
        self.smtp_port = config.get('smtp_port', 587)
        self.smtp_user = config.get('smtp_user')
        self.smtp_password = config.get('smtp_password')
        self.smtp_from = config.get('smtp_from')
        self.tmp_directory = config.get('tmp_directory', './tmp')
        self.nginx_dir = config.get('nginx_dir')
        self.nginx_prefix = config.get('nginx_prefix')

        self.processing_batch_size = config.get('processing_batch_size', 100)
        self.llm_thread_pool_max_worker = config.get('llm_thread_pool_max_worker', 10)
        self.kb_thread_pool_max_worker = config.get('kb_thread_pool_max_worker', 2)
        self.db_pool_size = config.get('db_pool_size', 16)

        self.send_email_type = config.get('send_email_type', 'techtanium')
        self.techtanium_tenant_id = config["techtanium_tenant_id"]
        self.techtanium_client_id = config["techtanium_client_id"]
        self.techtanium_client_secret = config["techtanium_client_secret"]
        self.techtanium_sender = config["techtanium_sender_email"]


settings = Settings()
